﻿var lang=new Object();
var SiteUrl='';
var AdminPath;
var SitePath;
var vg={};
if (!('trim' in String.prototype)) {
    String.prototype.trim = function() {
        return this.replace(/(^\s*)|(\s*$)/g, "");
    }
};
if (!('SubString' in String.prototype)) {
	String.prototype.SubString=function(size)
	{
		var totalCount = 0;  
		var newStr = ""; 
		for (var i=0; i<this.length; i++) {   
         var c = this.charCodeAt(i);  
         if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {  
             totalCount++;  
         }else {     
             totalCount+=2;  
         }  
         if(totalCount<size){ 
             newStr = this.substring(0,i+1); 
         }  
     } 
     return newStr; 
	}
};
if (!('EnCode' in String.prototype)) {
	String.prototype.EnCode=function()
	{
		 return /[^\x00-\xff]/g.test(this)?escape(this):this;
	}
};
Array.prototype.inArray = function(value)
{
	for(var i=0;i<this.length;i++)
	{
		if(value==this[i])
		{
			return true;
		}
	}
	return false;
};
if (!('incstr' in String.prototype)) {
    String.prototype.incstr = function(s, l) {
        var tmp = this;
        for (var i = tmp.length; i < l; i++) {
            tmp = s + "" + tmp;
        }
        return tmp;
    }
};
if (!('isUrl' in String.prototype)) {
	String.prototype.isUrl = function() {
		return /^(http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9%\-_@]+\.[A-Za-z0-9%\-_@]+[A-Za-z0-9\.\/=\?%\-&_~`@:\+!;]*$/.test(this);
	}
};
if (!('UrlParam' in String.prototype)) {
	String.prototype.UrlParam = function(name,value) {
		var s=this;
		if(typeof value=='undefined')
		{
			var re=new RegExp(name+'=(.*?)(?:&|$)','i');
			if(re.test(s)) return re.exec(s)[1];
		}
		else
		{
			var re=/\?/g;
			if(!re.test(s))s+="?";
			if(!/(\&$|\?$)/g.test(s))s+="&";
			re=new RegExp(name+'=(.*?)(?:&|$)','i');
			if(re.test(s))
			{
				var e=re.exec(s);
				s=s.replace(e[0],name+'='+value);
			}
			else s+=name+'='+value;
			return s;
		}
	}
};

					
					
if (!('format' in String.prototype)) {
	String.prototype.format = function() {
		var s=this;
		for(var i=0;i<arguments.length;i++)
		{
			s=s.replace(new RegExp("\\{" + i + "\\}", "g"), arguments[i]);
		}
		return s;
	}
};
Date.prototype.toString = function(t) {
    if (t) {
        var dt = new Date();
        var tmp = "";
        t = t.replace(/day/g, this - dt);
        t = t.replace(/age/g, dt.getFullYear() - this.getFullYear());
        t = t.replace(/yyyy/g, this.getFullYear());
        t = t.replace(/MM/g, String(this.getMonth() + 1).incstr('0', 2));
        t = t.replace(/M/g, this.getMonth() + 1);
        t = t.replace(/dd/g, String(this.getDate()).incstr('0', 2));
        t = t.replace(/d/g, this.getDate());
        t = t.replace(/hh/gi, String(this.getHours()).incstr('0', 2));
        t = t.replace(/h/gi, this.getHours());
        t = t.replace(/mm/g, String(this.getMinutes()).incstr('0', 2));
        t = t.replace(/m/g, this.getMinutes());
        t = t.replace(/ss/g, String(this.getSeconds()).incstr('0', 2));
        t = t.replace(/s/g, this.getSeconds());
        t = t.replace(/w/g, this.getDay());
        return t;
    } else return this.getFullYear() + "-" + (this.getMonth() + 1) + "-" + this.getDate();
};

function CacheTime()
{
	return new Date().toString("yyyy-MM-dd hh");
};
function JsPath()
{
	var elements = document.getElementsByTagName('script');
	var s=elements[elements.length-1].src.substring(0, elements[elements.length-1].src.lastIndexOf('/') + 1);
	if(s=='')s='./';
	var re=new RegExp("/$","g");
	if(!re.test(s))s+="/";
	return s;
};
function CheckInputPrice(obj,accuracy) {
		if(typeof accuracy == 'undefined')accuracy=2;
    return CheckInput(obj, /^\d*\.?\d{0,2}$/, String.fromCharCode(event.keyCode));
};
function CheckInputNumber(obj) {
    return CheckInput(obj, /^\d$/, String.fromCharCode(event.keyCode));
};
function CheckInput(obj, reg, inputStr) {
    var docSel = document.selection.createRange();
    if (docSel.parentElement().tagName != "INPUT") return false;
    oSel = docSel.duplicate();
    oSel.text = "";
    var srcRange = obj.createTextRange();
    oSel.setEndPoint("StartToStart", srcRange);
    var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length);    
    return reg.test(str);
};
function cookie(root, key, value, options)
{
	if(typeof CookiePrefix == "undefined")CookiePrefix="vIFO_";
	root = CookiePrefix + root;
	root = root.toLowerCase();
	var GetValue=function(cookie)
	{
			var re = new RegExp("\s?(.*?)=(.*?)(?:&|$)","g");
			var s1='{';
			var matches = /\w?(.*?)=(.*?)(?:&|$)/g.exec(cookie);
			while(matches=re.exec(cookie))
			{
				s1+=matches[1]+':"'+unescape(matches[2])+'",';
			}
			if(s1=='{')s1='';
			else s1=s1.replace(/,$/, '}');
			try
			{
				var json=eval('('+s1+')');
				return json;
			}catch(ex){return {};}
	};
	var SetValue=function(cookie,key,value)
	{
			var re = new RegExp(key+"=(.*?)(?:&|$)","gi");
			if(null==value)
				cookie=cookie.replace(re,'');
			else
			{
				var matches;
				var seted=false;
				while(matches=re.exec(cookie))
				{
					var s=key+'='+value;
					if(/\&$/g.test(matches[0]))s+="&";
					cookie=cookie.replace(re,s);
					seted=true;
				}
				if(!seted)
				{
					if(cookie!='')cookie+="&";
					cookie+=key+'='+value;
				}
			}
			return cookie;
	};
		
	if (typeof value != 'undefined') //设置Cookie
	{
		if(value!=null)
		{
			value+='';
			value=value.EnCode();
		}
		options = options || {};
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString))
		{
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
		}
		var path = options.path ? '; path=' + (options.path) : '';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		var cookies = {};
		var c = document.cookie + ";";
		var re = /\s?(.*?)=(.*?);/g;
		var matches;
		var seted=false;
		while ((matches = re.exec(c)) != null)
		{
	    if (matches[1] == root)
	    {	    	
	    	var cookie=SetValue(matches[2],key,value);
	    	document.cookie = [root, '=', cookie, expires, path, domain, secure].join('');
	    	seted=true;
	    	break;
    	}
   	}
   	if(!seted)
   	{
   		document.cookie = [root, '=', key+'='+value, expires, path, domain, secure].join('');
   	}
	}
	else
	{
		var cookies = {};
		var c = document.cookie + ";";
		var re = /\s?(.*?)=(.*?);/g;
		var matches;
		while ((matches = re.exec(c)) != null)
		{
			var name = matches[1];
	    var value = matches[2];
	    if (name == root)
	    {
				cookies=GetValue(value);
				return (eval('(cookies.'+key+')'));				
    	}
   	}
   	return null;
  }
}

function ShowPic(ImgD, maxwidth, maxheight) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= maxwidth / maxheight) {
            if (image.width > maxwidth) {
                ImgD.width = maxwidth;
                ImgD.height = (image.height * maxwidth) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > maxheight) {
                ImgD.height = maxheight;
                ImgD.width = (image.width * maxheight) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
    $(ImgD).show();
};
function ToJson(node,def)
{
	var field='({';
	$(node.attributes).each(function(i,item)
	{
		field+=item.name+':';
		if(item.value.toLowerCase()=='true' || item.value.toLowerCase()=='false')field+=item.value.toLowerCase();
		else if(!/^\-?[0-9]+$/gi.test(item.value))field+='"'+item.value.replace("\\","\\\\")+'"';
		else field+=item.value;
		field+=',';
	});
	field=field.replace(/,$/gi,'');
	field+='})';
	try{
		field=$.extend({},def, eval(field));
	}catch(ex)
	{
		field={};
	}
	return field;
}
function ShowMask()
{
	var DivMask=$("#DivMask");
	if(!DivMask.attr('id'))
	{
		DivMask=$("<div></div>").appendTo('body').attr("id","DivMask");
	}	
	//if(DivMask.find("iframe").size()<1)	$("<IFRAME style=\"width:1px;height:1px\"></IFRAME>").appendTo(DivMask);
	DivMask.css({position:"absolute",
			background:"#ccc",
			top:"0px",
			left:"0px",
			zIndex:"2",
			width:"100%",
			height:$('body').height(),
			opacity:0.4
			}).show();
};
function HideMask()
{
	$("#DivMask").hide();
};


function LoadJS(jsfile,_id)
{
	try{
		if(_id && $('#'+_id).size()>0) return;
		var js=document.createElement('script');
	  	js.setAttribute("type","text/javascript");
	  	js.setAttribute("id",_id);
	  	js.setAttribute("src", jsfile);
	  	document.getElementsByTagName("head")[0].appendChild(js);
	}catch(ex){}
};

function LoadCSS(cssfile,CallBack)
{
	try{
		var css=document.createElement("link");
	  css.setAttribute("type","text/css");
	  css.setAttribute("href", cssfile);
		css.setAttribute("rel", "stylesheet");
		if (CallBack)
		{
			css.onload=function()
			{
				if (css.readyState && css.readyState != 'loaded' && css.readyState != 'complete')
        return;
        css.onreadystatechange = css.onload = null;
        CallBack();
			};
		}
	  document.getElementsByTagName("head")[0].appendChild(css);
	}catch(ex){}
};
function RunScript(URL,CallBack)
{
	var script = document.createElement('script');
	script.type = "text/javascript";
	if (CallBack)
		script.onload = script.onreadystatechange = function() {
      if (script.readyState && script.readyState != 'loaded' && script.readyState != 'complete')
        return;
      script.onreadystatechange = script.onload = null;
      CallBack();
    };
	script.src=URL;	
	document.getElementsByTagName('head')[0].appendChild (script);
};

function GetPicUrl(url)
{
	return url.replace(/(_+?.*(\.[^\.]*)$)/i, "$2");
};
function GetThumbnailUrl(url)
{
	url=GetPicUrl(url);
	return url.replace(/(.*)(.*(\.[^\.]*)$)/g,"$1_Thumbnail$2");
};
function GetTagUrl(url,tag)
{
	url=GetPicUrl(url);
	return url.replace(/(.*)(.*(\.[^\.]*)$)/g,"$1"+tag+"$2");
};
function GetSquareUrl(url)
{
	url=GetPicUrl(url);
	return url.replace(/(.*)(.*(\.[^\.]*)$)/g,"$1_Square$2");
};
function DialogOnMove()
{
	
};
function ShowDialog(t,s,m,w,h)
{
	vg.dialog=$('body').Popup().Show({title:t,html:s,menu:m,width:w,height:h,ImagePath:(AdminPath||SitePath)+'files/images/Popup/'});
};
function HideDialog()
{
	vg.dialog.Hide();
	var box=$("#DialogBox");
	if(box.attr('id'))
	{
		box.hide();
	}
	HideMask();
};
(function($) {
	
	$.fn.ProgressBar=function(options)
	{
		var _this=this,
			options = jQuery.extend({
				min:0,
				max:100,
				text:'',
				width:0,
				height:0
			}, options || {});
		return this.each(function()
		{
			var span=$(this).find('span');
			var div=$(this).find('div');
			if(options.width>0)
			{
				$(this).width(options.width);
			}
			var p=Math.round(options.min/options.max*100);
			div.css({width:p+'%'});
			if(options.text=='')
				span.html(p+'%');
			else
				span.html(options.text.format(p+'%'));
			$(this).show();
		});
	};
	$.fn.tableSort=function(options)
	{
		var _this=this,
			tr=[],
			td=[],
			options = jQuery.extend({
				asc:'asc',
				desc:'desc',
				over:'over',
				line:'line1'
		}, options || {});
		this.Sort=function(obj)
		{
			var index=$(obj).parents("tr").find("th").index(obj);
			$(this).find('tbody > tr').each(function(i)
			{
				tr[i]=this;
				td[i]=$(this).find("td").eq(index)[0];
			});
			var asc=!$(obj).is('.'+options.desc);
			for(var i=0;i<td.length; i++)
			{
				for(j=i;j<td.length;j++)
				{
					if((asc==false && td[i].innerHTML<td[j].innerHTML) || (asc==true && td[i].innerHTML>td[j].innerHTML))
					{
						a=td[i];
						td[i]=td[j];
						td[j]=a;
					}
				}
			}
			var tbody=$(this).find("tbody").empty();
			for(var i=0;i<td.length;i++)
			{	
				var t=$(td[i]).parents("tr").appendTo(tbody);
				t.bind("mouseover",function(){ $(this).addClass(options.over);})
				.bind("mouseout",function(){$(this).removeClass(options.over);});
				if(i%2==0)t.addClass(options.line);
				else t.removeClass(options.line);
			};		
			if(asc)$(obj).addClass(options.desc).removeClass(options.asc);
			else $(obj).addClass(options.asc).removeClass(options.desc);
		};
		return this.each(function()
		{
			$(this).find("thead th").each(function()
			{
				if(!$(this).is('.nosort'))
				{
					$(this).click(function()
					{
						_this.Sort(this);
					});
				}
			});
		});
	};
	$.fn.UploadPreview=function(options)
	{
		options = jQuery.extend({
			filetypeerror:'请选择图片文件',
			imgtype:["gif", "jpeg", "jpg", "bmp", "png"],
			width:300,
			height:300

		
		}, options || {});
		var stage,_this=this,container=$(this).parent();
		this.autoScaling=function()
		{
			var img=stage.find("img");
			if ($.browser.version == "7.0" || $.browser.version == "8.0") img.get(0).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "image";
			var w = stage.width();
			var h = stage.height();
			if (w > 0 && h > 0)
			{
				var rate = (options.width / options.width < options.height / h) ? options.width / w : options.height / h;
				if (rate <= 1)
				{
					if ($.browser.version == "7.0" || $.browser.version == "8.0") img.get(0).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "scale";
					img.width(w*rate).height(h*rate);
				}
				//var left = (options.width - stage.width()) * 0.5;
				//var top = (options.height - stage.height()) * 0.5;
				//stage.css({ "margin-left": left, "margin-top": top });
				stage.show();
				$().bind("click",function(){
					stage.hide();
					$().unbind("click");
						});
			}
		};
		this.change(function()
		{
			if (!RegExp("\.(" + options.imgtype.join("|") + ")$", "i").test(this.value.toLowerCase())) 
			{
				alert(options.filetypeerror);
				this.value = "";
				return false;
			};
			stage=$(container).find(".uploadpreview_stage");
			if(stage.size()<1)
			{
				stage=$("<div></div>").appendTo(container).addClass("uploadpreview_stage").css({position:'absolute'});
				$("<img />").appendTo(stage).width(1);
			}
			stage.hide();
			if ($.browser.msie)
			{
				if ($.browser.version == "6.0")
				{
					var img = $("<img />");
					stage.find("img").replaceWith(img);
					var image = new Image();
					image.src = 'file:///' + this.value;
					stage.find("img").attr('src', image.src);
				}
				else
				{
					stage.find("img").css({filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image)" })
						.get(0).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = "image";
					try
					{
						stage.find("img").get(0).filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = this.value;
					}
					catch (e) 
					{
						return;
					}

				}
			}
			else
			{
				var img = $("<img />");
				stage.find("img").replaceWith(img);
				stage.find("img").attr('src', this.files.item(0).getAsDataURL());
				stage.find("img").css({ "vertical-align": "middle" });
			}
			$(_this).oneTime(1000,function(){_this.autoScaling();});
		});
		return this.each(function()
		{
			
		});
	};
	
	 $.extend($.fn, {
        getCss: function(key) {
            var v = parseInt(this.css(key));
            if (isNaN(v))
                return false;
            return v;
        }
    });
  $.extend($.fn,
  {
	  xml:function(options)
	  {
	  	var _this=this;
	  	this.loadXml=function(xmlstr)
	  	{
	  		if(typeof this.xmldoc =='undefined')this.GetXmlDoc();
	  		if(this.xmldoc)
				{
					try{
						if(window.ActiveXObject)
						{
							this.xmldoc.loadXML(xmlstr);
						}
						else
						{
								var oParser = new DOMParser();
								this.xmldoc = oParser.parseFromString(xmlstr,"text/xml");
						}
					}
					catch(ex)
					{
						this.xmldoc=null;
					}
				}
				return this;
	  	};
	  	this.GetXmlDoc=function()
	  	{
	  		if(window.ActiveXObject)
				{
					this.xmldoc	= new ActiveXObject('Microsoft.XMLDOM');
					this.xsldoc	= new ActiveXObject('Microsoft.XMLDOM');
					this.xsldoc.async	= false;
					this.xmldoc.async	= false;
					this.xmldoc.setProperty('SelectionLanguage','XPath');
					this.xsldoc.setProperty('SelectionLanguage','XPath');
				}
				else if (document.implementation&&document.implementation.createDocument)
				{
					this.xmldoc	= document.implementation.createDocument('', '', null);
					this.xsldoc	= document.implementation.createDocument('', '', null);
					this.xmldoc.async = false;
					this.xsldoc.async	= false;
				}
				return this;
	  	};
	  	return this.each(function()
	  	{
	  	});
	  }
  });
  $.fn.Popup=function(options)
  {
  	var _this = this,
  		_options={
  			title:'',
		 		html:'',
		 		width:450,
		 		height:350,
		 		minwidth:100,
		 		minheight:100,
		 		url:'',
		 		html:'',
		 		onMove:function(){},
		 		onDrop:function(){},
		 		onResize:function(){},
		 		onResized:function(){},
		 		WindowState:0, //0=Normal,1=Maximized,2=Minimized
		 		id:1,		 		
       	CustomCss:false,
       	ImagePath:'files/images/Popup/',
       	ImageExt:'.png',
       	fade:false,
       	StatusLine:false,
       	inited:false,
       	ShowButton:false,
       	ShowClose:true,
       	Buttons:[],
       	page:this,
       	showMask:true
  			},
  		options = jQuery.extend(false,_options, options || {})
       ,container=null
       ,head=null
       ,title=null
       ,main=null
       ,StatusLine=null
       ,DivMask=null
       ,Showing=false
       ,ButtonBar=null
       ,containerborder;
       this.options=options,
       WindowID=0;
       
  	var EventDrag=
  	{
	  	Drag:function(e)
	  	{	  		
				var data = e.data;
				data.container[0].setCapture();
				var pos={x:(options.direction=="y")?(data.left):(data.left + e.pageX - data.offLeft),y:(options.direction=="x")?(data.top):(data.top + e.pageY - data.offTop)};
				if(pos.y<1)pos.y=0;
				data.container.css({
					left:pos.x,//(options.direction=="y")?(data.left):(data.left + e.pageX - data.offLeft),
					top: pos.y//(options.direction=="x")?(data.top):(data.top + e.pageY - data.offTop)
				});
				data.onMove(e);
	  	},
	  	Drop:function(e)
	  	{
				e.data.container[0].releaseCapture();
				//$("#m_sitename").html('un'+e.pageX);
	  		$(options.page).unbind('mousemove', EventDrag.Drag)
	  				 .unbind('mouseup',  EventDrag.Drop);
	  		e.data.container.css("border",e.data.containerborder);
				e.data.onDrop(e);
				e.data.container.removeClass('popup_keydown');
	  	}
	  }
	  var EventResize=
	  {
	  	Resize:function(e)
	  	{
	  			var data=e.data;
	  			var w=data.width-(data.offLeft-e.pageX);
  				if(options.minwidth>0 && w<=options.minwidth)w=options.minwidth;
  				var h=data.height-(data.offTop-e.pageY);
  				//if(options.minheight>0 && h<=options.minheight)h=options.minheight;
  				main.html(w+'-'+h+'=='+data.height);
	  	},
	  	Resized:function(e)
	  	{
	  		$(options.document).unbind('mousemove', EventResize.Resize).unbind('mouseup',  EventResize.Resized);
  			e.data.onResized(e);
	  	}
	  };
  	this.Resize=function(e)
  	{
  		var data=e.data;
  		main.html(data.offLeft+"=="+e.pageX);
  		return;
  		var w=data.width-(data.offLeft-e.pageX);
  		if(options.minwidth>0 && w<=options.minwidth)w=options.minwidth;
  		var h=data.height-(data.offTop-e.pageY);
  		if(options.minheight>0 && h<=options.minheight)h=options.minheight;
  		container.width(w)
  			.height(h);
  		var mh=container.height()-head.height();
  		if(options.StatusLine==true)mh-=StatusLine.height();
  		if(options.ShowButton===true && options.Buttons.length>0)mh-=ButtonBar.height();
  		//main.height(mh);
			e.data.onResize(e);
  	};
  	this.Resized=function(e)
  	{
  		$(options.page).unbind('mousemove', _this.Resize).unbind('mouseup',  _this.Resized);
  		e.data.onResized(e);
  		main.html('hi');
  	};
		this.Size=function()
		{
			return $(options.page).find(".popupcontainer").size();
		}
		this.zIndex=function(obj)
		{
			var i=0;
			$(options.page).find(".popupcontainer").each(function()
			{
				var t=parseInt($(this).css("zIndex"));
				if(isNaN(t))t=0;
				if(t>i)i=t;
			});
			i++;
			if($(obj).attr("class")!="popupcontainer")obj=$(obj).parents(".popupcontainer");			
			$(obj).css({zIndex:i});
		};
		this.GetOptions=function()
		{
			return options;
		};
		this.Open=function(opt)
		{
			options = jQuery.extend(options,opt ||{});
  		this.Init();
  		if(options.showMask==true)this.Mask();
  		if(options.fade==true)
  			container.fadeIn("slow");
  		else
  			container.show();
  		this.SetWindowState();
  		
  		return this;
		};
		this.Show=function(opt,newDialog)
  	{
			options = jQuery.extend(options,opt ||{});
  		if(typeof newDialog=='undefined' || newDialog==true)this.Open();
  		title.html(options.title);
  		main.empty();
  		if(options.url!='' && typeof options.url!='undefined')
			{
				options.url=options.url.UrlParam('popupwindowid',options.id);
				var pid=parseInt($.query.get('popupwindowid'));
				if(isNaN(pid))pid=0;
				if(pid>0)	options.url=options.url.UrlParam('popupparentwindowid',pid);
				title.html('Loading');
				main.empty();
				var iframe=$('<iframe frameborder="0" scrolling="auto" allowtransparency="true"></iframe>')
					.css({width:'100%',height:'100%',border:'0'}).attr('name','frame_'+options.id);
				iframe.bind("load",function()
					{
						try{
							var cw=$(this.contentWindow.document);
							title.html(cw.find("title").html());
							var t=cw.find('input[type=text]:visible');
							if(t.length>0)
							{
								t.focus();
							}
							else
							{
								t=cw.find('textarea:visible').focus();
							}
						}catch(e){}
					}).appendTo(main).attr('src',options.url);
			}else if(typeof options.control!='undefined' && options.control.length>0)
			{
				$(options.control).appendTo(main.empty());
			}
			else
			{
				main.html(options.html);
			}
			this.zIndex(container);
			this.SetWindowState();
  		return this;
  	};
  	
		this.Hide=function(obj)
		{
			try{
				if(options.OnScroll==true) $(options.document.body).unbind('scroll');
				if(typeof options.closeEvent=='function')options.closeEvent();
				if(typeof obj !='undefined')container=$(obj);
				if(!container || container.size()<1)container=$(options.document.page).find("#popupcontainer_"+options.id);
				if(!DivMask || DivMask.size()<1)DivMask=$(options.document.page).find("#"+options.id+"_DivMask");	
				if(options.fade==true)
				{
					container.fadeOut("slow",function()
					{
						$(this).remove();
						if(_this.Size()<1)
						{
							DivMask.fadeOut("slow",function()
							{
								$(this).remove();
							});
						}
					});
					
				}
				else
				{
					container.remove();
					if(this.Size()<1) DivMask.remove();
				}
			}catch(ex){}
			return this;
		};
		this.SetOptions=function(opt)
		{
			options = jQuery.extend(options,opt ||{});
			return this;
		};
		this.SetWindowState=function()
		{
  		if(/^\-?[0-9]+$/.test(options.width))options.width+="px";			
			if(/^\-?[0-9]+$/.test(options.height))options.height+="px";	
			container.css({
  			width:options.width,
  			height:options.height,
  			position:'absolute'
  			
  		});
  		switch(options.WindowState)
  		{
  			case 1:
  				container.width("100%").height("100%");
  			break;
  			default:
  				container.width(options.width).height(options.height);					
  			break;
  		}
			if(options.height!='auto')
			{
	  		var mh=container.height()-head.height();
	  		if(options.StatusLine==true)mh-=StatusLine.height();
	  		if(options.ShowButton===true && options.Buttons.length>0)mh-=ButtonBar.height();  		
	  		if(options.StatusLine==true)
	  		{
	  			StatusLine.show();
	  		}
	  		else
	  		{
	  			StatusLine.hide();
	  		}
	  		main.height(mh);
	  	}
	  	var pos={};
	  	if(options.WindowState==1)
	  	{
	  		pos.top=0;
	  		pos.left=0;
	  	}
	  	else
	  	{
	  		pos={top:(document.documentElement.clientHeight/2)-(container.height()/2),left:(document.documentElement.clientWidth/2)-(container.width()/2)};
	  	}
	  	if(pos.top<0)pos.top=0;
			container.css({
  			left:pos.left,
  			top:pos.top+$(options.page).scrollTop()
  		});
  		if(options.OnScroll==true)
  		{
  			
  			$(options.document.body).bind('scroll',function(){
					_this.OnScroll();
				});
  		}
			this.OnScroll();
		};
		this.OnScroll=function()
		{
			if(options.WindowState==1)return this;
			
			var pos={top:(options.document.documentElement.clientHeight/2)-(container.height()/2),left:(options.document.documentElement.clientWidth/2)-(container.width()/2)};
			pos.scrollTop=options.document.body.scrollTop|options.document.documentElement.scrollTop;			
			container.css({
  			left:pos.left,
  			top:pos.top+pos.scrollTop
  		});
		};
  	this.Mask=function()
  	{
  		DivMask=$(options.page).find("#"+options.id+"_DivMask");
  		if(DivMask.size()<1)
  		{
				DivMask=$("<div></div>").appendTo($(options.page))
					.attr("id",options.id+"_DivMask")
					.css({position:"absolute",
						background:"#ccc",
						top:"0px",
						left:"0px",
						zIndex:"2",
						width:"100%",
						height:$().height(),// document.documentElement.clientHeight,
						filter:'alpha(Opacity=50)',
						opacity:'0.5'
					});
				$("<IFRAME style=\"width:100%;height:100%;filter:alpha(opacity=0);-moz-opacity:0\"></IFRAME>").appendTo(DivMask);
			}
			DivMask.show();
		};
		this.GetWindow=function(id)
		{
			var box=$(options.page).find("#popupcontainer_"+id)
			var frame=box.find("iframe");
			if(frame.size()>0)
				return frame[0].contentWindow;
			else
				return box;
		};
		this.Init=function()
		{
			if(options.ImageExt==".png")
  		{
  			if($.browser.msie && $.browser.version=="6.0")
					options.ImageExt=".gif";
  		}
  		if(typeof options.document =='undefined') options.document=document;
  		options.page=options.document.body;
  		options.id=this.Size()+1;
  		//container=$(options.page).find("#"+options.id);
  		container=$("<div></div>").attr("id",'popupcontainer_'+options.id).hide().addClass('popupcontainer').click(function()
			{				
  				_this.zIndex(this);
			}).appendTo($(options.page));
  		if(container===null)return this;
  		head=container.find("."+options.id+"_head");
  		if(head.length<1)head=$("<div></div>").addClass(options.id+"_head").appendTo(container).addClass('popup_head');
  		title=$(head).find("."+options.id+"_title");
  		if(title.length<1)title=$("<div></div>").appendTo(head).addClass(options.id+"_title").addClass('popup_title');
  		var _close=head.find("."+options.id+"_close");
  		if(_close.length<1)_close=$("<div><a href='javascript:'></a></div>").appendTo(head).addClass(options.id+"_close").addClass('popup_close');
			_close.find('a').click(function()
  		{
  			_this.Hide($(this).parents(".popupcontainer"));
  		});
  		if(options.ShowClose==false)_close.hide();
  		main=container.find("."+options.id+"_main");
  		if(main.length<1)main=$("<div></div>").appendTo(container).addClass(options.id+"_main").addClass('popup_main');
  		if(options.ShowButton===true && options.Buttons.length>0)
  		{
  			ButtonBar=container.find("."+options.id+"_button");
  			if(ButtonBar.size()<1)ButtonBar=$("<div></div>").appendTo(container).addClass(options.id+'_button').addClass('popup_button');
  			ul=$(ButtonBar).find("ul");
  			if(ul.size()<1)	ul=$("<ul></ul>").appendTo(ButtonBar);
  			
  			$(options.Buttons).each(function(i,item)
  			{
  				var li=$("<li></li>").appendTo(ul);
  				var button=$("<input type='button' />").appendTo(li)
  					.attr('value',item.text)
  					.attr('id',item.id||options.id+'_button_'+i);
  				if(item.event)
  				{
	  				$(item.event).each(function()
	  				{
	  					if(typeof this.name !='undefined' && typeof this.fun=='function')	  					
	  						button.bind(this.name,this.fun);
	  				});
	  			}
  			});
  			if(options.CustomCss===false)
				{
					ButtonBar.css({float:'left',
						width:'100%',
						height:'24px',
						lineHeight:'24px',
						background:'#EFEFEF'});
					ul.css({float:'right',
						height:'24px',
						lineHeight:'24px',marginTop:'1px'});
					ul.find("li").css({float:'left',marginRight:'5px'});
					ul.find("input").css({
						backgroundImage:"url("+options.ImagePath+"bg"+options.ImageExt+")",
						backgroundRepeat:"repeat-x",
						backgroundPosition:'0 -95px',
						border:'1px solid #D6D9DC',
						height:'20px',
						lineHeight:'20px',
						cursor:'pointer'
					}).hover(function()
					{
						$(this).css({backgroundPosition:'0 -73px'});
					},function()
					{
						$(this).css({backgroundPosition:'0 -95px'});
					});
				}
  		}else options.ShowButton=false;
  		StatusLine=$(container).find("."+options.id+"_statusline");
  		if(StatusLine.length<1)StatusLine=$("<div><div></div></div>").appendTo(container).addClass(options.id+"_statusline");
  		if(options.StatusLine==true)StatusLine.show();else StatusLine.hide();
  	
  		if(options.CustomCss===false)
  		{
  			options.inited=true;
  			container.css({
  				border:"1px solid #6d98c2",
  				zIndex:'10',
  				wordBreak:'break-all'
  			});
  			head.css({
  				backgroundImage:"url("+options.ImagePath+"bg"+options.ImageExt+")",
  				backgroundRepeat:"repeat-x",
  				width:100+'%',
  				height:'28px',
  				lineHeight:'28px',
  				float:"left",
  				color:'#ffffff'		
  			});
  			title.css({float:'left',textIndent:'2em'});
  			_close.css({float:'right',width:'37px',height:'19px',lineHeight:'19px'});
  			_close.find("a").each(function()
  			{
  				$(this).css(
  					{backgroundImage:'url('+options.ImagePath+'bg'+options.ImageExt+')',
  					backgroundPosition:'0 -30px',display:'block',float:'left',width:'100%',height:'19px',
  					cursor:'pointer'
  					
  					})
  				.hover(function()
  				{
  					$(this).css({backgroundPosition:'-37px -30px'});
  					//head.unbind("mousedown");
  				},function(){
  					$(this).css({backgroundPosition:'0 -30px'});
  				});

  			});  			
  			main.css({backgroundColor:"#ffffff",float:"left",width:"100%"});  		
  			
  			
				if(options.WindowState==1)
				{
					container.width("100%")
						.height("100%");
				}
				StatusLine.css({float:'left',width:'100%',height:'20px',lineHeight:'20px',
					backgroundColor:"#f3f3f3"}).find("div").each(function()
				{
					$(this).css({float:'right',width:'16px',height:'20px',cursor:'nw-resize',
						backgroundImage:"url("+options.ImagePath+"bg"+options.ImageExt+")",
  					backgroundRepeat:"repeat-x",
  					backgroundPosition:'100% -139px'
  				});
				});
				if(options.StatusLine==true)
				{
					var d1=StatusLine.find("div");
						var data = {
							container: container,
							bar:d1,
							onResize: options.onResize,
							onResized: options.onResized,
							width:container.width(),
							height:container.height()
						};
					
					d1.bind("mousedown",function(s)
					{
						data.offLeft=s.pageX;
						data.offTop=s.pageY;
						data.container=container;
						$(options.document).bind('mousemove', data, EventResize.Resize).bind('mouseup',data, EventResize.Resized);
	  				
  				})
				}
  		}
  			head.dblclick(function()
  			{
  				if(options.WindowState==1)options.WindowState=0;
  				else options.WindowState=1;
  				_this.SetWindowState();
  			}).bind('mousedown',{container:container}, function(s) 
				{
  				//containerborder=container.css("border");
  				container.addClass('popup_keydown');
					$(this).css({cursor:'move'});
					var e=s.data;
					e.container=$(e.container);
					var data = {
							left: e.container.left || e.container.getCss('left') || 0,
							top: e.container.top || e.container.getCss('top') || 0,
							width: e.container.width(),
							height: e.container.height(),
							offLeft: s.pageX,
							offTop: s.pageY,
							onMove: options.onMove,
							onDrop: options.onDrop,
							handler: head,
							container: e.container,
							containerborder:containerborder
					};
					//container.css({border:"1px dashed #cccccc"});
					$(options.page).bind('mousemove', data, EventDrag.Drag)
  				 .bind('mouseup', data, EventDrag.Drop);
				});
		};
		return this.each(function()
		{
			if(typeof options.document =='undefined')options.document=document;
			if(typeof options.page=='undefined')options.page=options.document.body;
		});
  };
	
	
    $.fn.Tabs = function(options) {
        var _this = this;
        var lis;
        this.index = 0;
        this.items = new Array();
        this.current;
        options = jQuery.extend({
            cssCurrent: "current",
            target:"_blank",
            eventreturn:true,
            index:0
        }, options || {});

        this.id=document.location.href;
        this.id=this.id.split("#");
        if(this.id.length>1)this.id=this.id[this.id.length-1];
        else this.id='';
        this.GoToUrl=function(index)
        {
        	lis = $(this).find('li:[url]', this.element);
        	var li=$(lis[index]);
        	var url=li.attr('url');
        	if(url.trim()=='')return this;
        	var r=new RegExp(url.replace(/(#.*$)?/gi,'')+'(#.*$)?','gi');
        	if(!r.test(document.location.href))
        	{
        		document.location.href=url;
        	}
        };
        this.SetIndex=function(index)
        {
        	options.inited=true;
					lis = $(this).find('li:[url]', this.element);
					lis.each(function(i)
					{
						$(this).removeClass(options.cssCurrent).removeClass(options.cssCurrent+index);
					});
					lis.parent().removeClass('tabs_index_'+this.index).addClass('tabs_index_'+index);
					var li=$(lis[index]).addClass(options.cssCurrent).addClass(options.cssCurrent+index);
					this.index = index;
					this.current=li;
					$(this.items).each(function(i,item)
					{
							try{
								if(_this.items[index].id=="expandall" || i==index)
            			$("#" + this.id).show();
            		else $("#" + this.id).hide();
            	}catch(e){}
					});
					if(typeof options.callback=='function')
						options.callback(_this);
					return this;
        };
        this.add=function(par)
        {
        	var li=$("<li></li>").appendTo(this).addClass(options.cssCurrent);
        	var span=$("<span></span>").appendTo(li);
        	span.html(par.title);
        	return this;
        };
        return this.each(function() {
        		options.inited=false;
            lis = $(this).find('li:has(a[href])', this.element);
            lis.each(function(i) {
            		if($(this).is('.notab'))
            		{
            			_this.items[i]={};
            			return true;
            		}
            		$(this).css('cursor','pointer');
                var a = $(this).find("a");
                var url = a.attr("href");
                var s1 = url.split("#");
                var s2="";
                var id = "";
                if (s1.length > 1)
                {
                	s2=s1[0];
                	id = s1[1];
                }
                if(id=="")
                {
	                var did=$(this).attr('did');
	                if(did!=undefined && did!='')id=did;
	              }
	              if(id!="")
	              {
	              	if(!options.event)
	              	{
	              		if (s2 == "")
	              		{
	              			$(this).click(function() { _this.SetIndex(i);_this.GoToUrl(i);});
	              			a.attr('href','javascript:').attr("onclick", "return false");
	              		}
	              		else {
	              			$(this).hover(function() { _this.SetIndex(i);});
	              			a.attr("target", options.target);
	              		}
	              	}
	              	else
	              	{
	              		if(options.event=='mouseover')
	              		{
	                  		a.attr("target", options.target);
	              		}
	              		else
	              		{
	                  		a.removeAttr('href');
	              		}
	              		$(this).bind(options.event,function() { _this.SetIndex(i);_this.GoToUrl(i);});
	              	}
                }
                $(this).attr('tid',id).attr('url',url);                
                _this.items[i] = { url: url, title: a.html(), id: id };
                if(_this.items[i].id!='')
                {
									try{$('#'+_this.items[i].id).hide()}catch(ex){}
	              }
                if(_this.items[0].id=="expandall")
                {
                	$("#" + _this.items[i].id).show();
	              }
                else
                {
                	if(_this.id=='' && i == options.index)
		              {
		              	_this.SetIndex(i);
		              } 
		              else if(_this.id!='' && _this.id==_this.items[i].id)
	                {
	                	_this.SetIndex(i);
	                }
	                else if(options.currentid && options.currentid==_this.items[i].id)
									{
	                	_this.SetIndex(i);
									}else if(i==0){_this.SetIndex(i);}
								}
            });
        });			
    };
    
	var vFlash = $.fn.vFlash = function(options) {
		var _settings={
			width:0,
			height:0,
			barwidth:0,
			barheight:0,
			showbar:false,
			params:[],
			flashvars:[],
			transparent:false,
			classid:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
			pluginspage: 'http://www.adobe.com/go/getflashplayer',
			type:"application/x-shockwave-flash",
			data:""
		},
		htmlContent="",
		containerid="";
		var settings=jQuery.extend(false,_settings,options || {});
		this.show=function()
		{
			$(this).html(htmlContent);
			return this;
		};
		this.toString=function()
		{
			return htmlContent;
		};
		this.appendTo=function(containerid)
		{			
			var obj=$("#"+containerid);
			if(obj.size()>0)
				obj.html(htmlContent);
			return this;
		};
		return this.each(function()
		{
			if(settings.width<1)settings.width=$(this).width();
			if(settings.height<1)settings.height=$(this).height();
			containerid=$(this).attr("id");
			if(typeof containerid == undefined || containerid=="")containerid="vFlash";
			if(settings.id)containerid=settings.id;
			var fw=settings.width;
			var fh=settings.height;
			htmlContent="<div class='vflash' style='width:"+fw+"px;height="+fh+"px'>";
			htmlContent+="<object type='"+settings.type
				+"' id='"+containerid+"' width='"+settings.width+"' height='"+settings.height+"' data='"+settings.data
				+"' classid='"+settings.classid+"'>";
			htmlContent+="<param name='movie' value='"+settings.data+"' />";
			if(settings.transparent)settings.params.push({name:"wmode",value:"Transparent"});
			$(settings.params).each(function()
			{
				htmlContent+="<param name='"+this.name+"' value='"+this.value+"' />";
			});
			var vars="";			
			$(settings.flashvars).each(function(i)
			{
				vars+=this.name+"="+this.value+"&";	
			});
			vars=vars.replace(/&$/, '');
			if(vars!="")
				htmlContent+="<param name='flashvars' value='"+vars+"' />";
			htmlContent+="<embed src='"+settings.data+"' width='"+settings.width
				+"' height='"+settings.height+"' quality='high' pluginspage='"
				+settings.pluginspage+"' type='"+settings.type+"'";
			if(settings.transparent)htmlContent+=" wmode='transparent'";
			if(vars!="")htmlContent+=" flashvars='"+vars+"'";
			htmlContent+="></embed>";
			htmlContent+="</object></div>";
		});
	};
	vFlash.playerVersion = function() {
		try {
			try {
				var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
				try { axo.AllowScriptAccess = 'always';	}
				catch(e) { return '6,0,0'; }
			} catch(e) {}
				return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
			} catch(e) {
				try {
					if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
						return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
					}
				} catch(e) {}
				}
				return '0,0,0';
	};
	
	
})(jQuery);

/**
 * jQuery.timers - Timer abstractions for jQuery
 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
 * Date: 2009/10/16
 *
 * @author Blair Mitchelmore
 * @version 1.2
 *
 **/

jQuery.fn.extend({
	everyTime: function(interval, label, fn, times) {
		return this.each(function() {
			jQuery.timer.add(this, interval, label, fn, times);
		});
	},
	oneTime: function(interval, label, fn) {
		return this.each(function() {
			jQuery.timer.add(this, interval, label, fn, 1);
		});
	},
	stopTime: function(label, fn) {
		return this.each(function() {
			jQuery.timer.remove(this, label, fn);
		});
	}
});

jQuery.extend({
	timer: {
		global: [],
		guid: 1,
		dataKey: "jQuery.timer",
		regex: /^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,
		powers: {
			// Yeah this is major overkill...
			'ms': 1,
			'cs': 10,
			'ds': 100,
			's': 1000,
			'das': 10000,
			'hs': 100000,
			'ks': 1000000
		},
		timeParse: function(value) {
			if (value == undefined || value == null)
				return null;
			var result = this.regex.exec(jQuery.trim(value.toString()));
			if (result[2]) {
				var num = parseFloat(result[1]);
				var mult = this.powers[result[2]] || 1;
				return num * mult;
			} else {
				return value;
			}
		},
		add: function(element, interval, label, fn, times) {
			var counter = 0;
			
			if (jQuery.isFunction(label)) {
				if (!times) 
					times = fn;
				fn = label;
				label = interval;
			}
			
			interval = jQuery.timer.timeParse(interval);

			if (typeof interval != 'number' || isNaN(interval) || interval < 0)
				return;

			if (typeof times != 'number' || isNaN(times) || times < 0) 
				times = 0;
			
			times = times || 0;
			
			var timers = jQuery.data(element, this.dataKey) || jQuery.data(element, this.dataKey, {});
			
			if (!timers[label])
				timers[label] = {};
			
			fn.timerID = fn.timerID || this.guid++;
			
			var handler = function() {
				if ((++counter > times && times !== 0) || fn.call(element, counter) === false)
					jQuery.timer.remove(element, label, fn);
			};
			
			handler.timerID = fn.timerID;
			
			if (!timers[label][fn.timerID])
				timers[label][fn.timerID] = window.setInterval(handler,interval);
			
			this.global.push( element );
			
		},
		remove: function(element, label, fn) {
			var timers = jQuery.data(element, this.dataKey), ret;
			
			if ( timers ) {
				
				if (!label) {
					for ( label in timers )
						this.remove(element, label, fn);
				} else if ( timers[label] ) {
					if ( fn ) {
						if ( fn.timerID ) {
							window.clearInterval(timers[label][fn.timerID]);
							delete timers[label][fn.timerID];
						}
					} else {
						for ( var fn in timers[label] ) {
							window.clearInterval(timers[label][fn]);
							delete timers[label][fn];
						}
					}
					
					for ( ret in timers[label] ) break;
					if ( !ret ) {
						ret = null;
						delete timers[label];
					}
				}
				
				for ( ret in timers ) break;
				if ( !ret ) 
					jQuery.removeData(element, this.dataKey);
			}
		}
	}
});

jQuery(window).bind("unload", function() {
	jQuery.each(jQuery.timer.global, function(index, item) {
		jQuery.timer.remove(item);
	});
});
new function(settings) { 
  // Various Settings
  var $separator = settings.separator || '&';
  var $spaces = settings.spaces === false ? false : true;
  var $suffix = settings.suffix === false ? '' : '[]';
  var $prefix = settings.prefix === false ? false : true;
  var $hash = $prefix ? settings.hash === true ? "#" : "?" : "";
  var $numbers = settings.numbers === false ? false : true;
  
  jQuery.query = new function() {
    var is = function(o, t) {
      return o != undefined && o !== null && (!!t ? o.constructor == t : true);
    };
    var parse = function(path) {
      var m, rx = /\[([^[]*)\]/g, match = /^([^[]+)(\[.*\])?$/.exec(path), base = match[1], tokens = [];
      while (m = rx.exec(match[2])) tokens.push(m[1]);
      return [base, tokens];
    };
    var set = function(target, tokens, value) {
      var o, token = tokens.shift();
      if (typeof target != 'object') target = null;
      if (token === "") {
        if (!target) target = [];
        if (is(target, Array)) {
          target.push(tokens.length == 0 ? value : set(null, tokens.slice(0), value));
        } else if (is(target, Object)) {
          var i = 0;
          while (target[i++] != null);
          target[--i] = tokens.length == 0 ? value : set(target[i], tokens.slice(0), value);
        } else {
          target = [];
          target.push(tokens.length == 0 ? value : set(null, tokens.slice(0), value));
        }
      } else if (token && token.match(/^\s*[0-9]+\s*$/)) {
        var index = parseInt(token, 10);
        if (!target) target = [];
        target[index] = tokens.length == 0 ? value : set(target[index], tokens.slice(0), value);
      } else if (token) {
        var index = token.replace(/^\s*|\s*$/g, "");
        if (!target) target = {};
        if (is(target, Array)) {
          var temp = {};
          for (var i = 0; i < target.length; ++i) {
            temp[i] = target[i];
          }
          target = temp;
        }
        target[index] = tokens.length == 0 ? value : set(target[index], tokens.slice(0), value);
      } else {
        return value;
      }
      return target;
    };
    
    var queryObject = function(a) {
      var self = this;
      self.keys = {};
      
      if (a.queryObject) {
        jQuery.each(a.get(), function(key, val) {
          self.SET(key, val);
        });
      } else {
        jQuery.each(arguments, function() {
          var q = "" + this;
          q = q.replace(/^[?#]/,''); // remove any leading ? || #
          q = q.replace(/[;&]$/,''); // remove any trailing & || ;
          if ($spaces) q = q.replace(/[+]/g,' '); // replace +'s with spaces
          
          jQuery.each(q.split(/[&;]/), function(){
            var key = unescape(this.split('=')[0] || "").toLowerCase();
            var val = unescape(this.split('=')[1] || "");
            
            if (!key) return;
            
            if ($numbers) {
              if (/^[+-]?[0-9]+\.[0-9]*$/.test(val)) // simple float regex
                val = parseFloat(val);
              else if (/^[+-]?[0-9]+$/.test(val)) // simple int regex
                val = parseInt(val, 10);
            }
            
            val = (!val && val !== 0) ? true : val;
            
            if (val !== false && val !== true && typeof val != 'number')
              val = val;
            
            self.SET(key, val);
          });
        });
      }
      return self;
    };
    
    queryObject.prototype = {
      queryObject: true,
      has: function(key, type) {
        var value = this.get(key);
        return is(value, type);
      },
      GET: function(key) {
      	key=key.toLowerCase();
        if (!is(key)) return this.keys;
        var parsed = parse(key), base = parsed[0], tokens = parsed[1];
        var target = this.keys[base];
        while (target != null && tokens.length != 0) {
          target = target[tokens.shift()];
        }
        return typeof target == 'number' ? target : target || "";
      },
      get: function(key) {
        var target = this.GET(key);
        if (is(target, Object))
          return jQuery.extend(true, {}, target);
        else if (is(target, Array))
          return target.slice(0);
        return target;
      },
      SET: function(key, val) {
        var value = !is(val) ? null : val;
        var parsed = parse(key), base = parsed[0], tokens = parsed[1];
        var target = this.keys[base];
        this.keys[base] = set(target, tokens.slice(0), value);
        return this;
      },
      set: function(key, val) {
        return this.copy().SET(key, val);
      },
      REMOVE: function(key) {
        return this.SET(key, null).COMPACT();
      },
      remove: function(key) {
        return this.copy().REMOVE(key);
      },
      EMPTY: function() {
        var self = this;
        jQuery.each(self.keys, function(key, value) {
          delete self.keys[key];
        });
        return self;
      },
      load: function(url) {
        var hash = url.replace(/^.*?[#](.+?)(?:\?.+)?$/, "$1");
        var search = url.replace(/^.*?[?](.+?)(?:#.+)?$/, "$1");
        return new queryObject(url.length == search.length ? '' : search, url.length == hash.length ? '' : hash);
      },
      empty: function() {
        return this.copy().EMPTY();
      },
      copy: function() {
        return new queryObject(this);
      },
      COMPACT: function() {
        function build(orig) {
          var obj = typeof orig == "object" ? is(orig, Array) ? [] : {} : orig;
          if (typeof orig == 'object') {
            function add(o, key, value) {
              if (is(o, Array))
                o.push(value);
              else
                o[key] = value;
            }
            jQuery.each(orig, function(key, value) {
              if (!is(value)) return true;
              add(obj, key, build(value));
            });
          }
          return obj;
        }
        this.keys = build(this.keys);
        return this;
      },
      compact: function() {
        return this.copy().COMPACT();
      },
      toString: function() {
        var i = 0, queryString = [], chunks = [], self = this;
        var encode = function(str) {
          str = str + "";
          if ($spaces) str = str.replace(/ /g, "+");
          
          return escape(str);
        };
        var addFields = function(arr, key, value) {
          if (!is(value) || value === false) return;
          var o = [encode(key)];
          if (value !== true) {
            o.push("=");
            o.push(encode(value));
          }
          arr.push(o.join(""));
        };
        var build = function(obj, base) {
          var newKey = function(key) {
            return !base || base == "" ? [key].join("") : [base, "[", key, "]"].join("");
          };
          jQuery.each(obj, function(key, value) {
            if (typeof value == 'object') 
              build(value, newKey(key));
            else
              addFields(chunks, newKey(key), value);
          });
        };
        
        build(this.keys);
        
        if (chunks.length > 0) queryString.push($hash);
        queryString.push(chunks.join($separator));
        
        return queryString.join("");
      }
    };
    
    return new queryObject(location.search, location.hash);
  };
  
  
}(jQuery.query || {}); // Pass in jQuery.query as settings object
